const api = require('../../../ws_micro_shop/utils/api.js');
const app = getApp();

Page({
  data: {
    block: false,
    active: '',
    total_price: 0,
    price: 0,
    cash_price: 0,
    un_pay: 0,
    theme: app.themeData,
    unit: '',
  },
  onLoad(options) {
    let that = this;
    let commission_alias = decodeURIComponent(options.title);
    commission_alias && wx.setNavigationBarTitle({
      title: '分销' + commission_alias || '分销佣金',
    });
    app.pageOnLoad(this);
    app.loadCurrencyUnit().then(res => {
      that.setData({
        unit: res.unit,
        commission_alias: commission_alias,
      });
    });
  },
  onShow() {
    let page = this;
   
    wx.showLoading({
      title: '正在加载',
      mask: true,
    });
    app.ws_micro_shoprequest({
      url: api.share.get_price,
      success: function (res) {
        if (res.code === 0) {
          page.setData({
            total_price: res.data.price.total_price,
            price: res.data.price.price,
            cash_price: res.data.price.cash_price,
            total_cash: res.data.price.total_cash,
            un_pay: res.data.price.un_pay,
            rules: res.data.share_setting,
          });
        }
      },
      complete: function () {
        wx.hideLoading();
      },
    });
  },
  tapName(e) {
    let page = this;
    let active = '';
    if (!page.data.block) {
      active = 'active';
    }
    page.setData({
      block: !page.data.block,
      active: active,
    });
  },
  collectFormId(e) {
    app.collectFormId(e);
  },
});
